<?php
/*
 * @Author: SunnyJ
 * @Date: 2021-05-21 19:40:04
 * @LastEditors: SunnyJ
 * @LastEditTime: 2021-06-02 11:51:43
 */
namespace app\api\controller;
use think\Db;

class Invoice extends Base2 {

    /**
     * @description: 电子发票接口
     * @param {*} $token
     * @param {*} $platformCode
     * @param {*} $order_ids
     * @return {*}
     */    
    public function getInvoiceList($token,$platformCode,$order_ids) {
        // 验证token与platformCode
        $auth = Auth2::check_token($token,$platformCode);
        if (!$auth['result']) {
            return $this -> create('', $auth['msg'], false);
        }
        // 按','分割字符串
        $order_ids = explode(',',$order_ids);
        $result = [];
        foreach ($order_ids as &$order_no) {
            $order_id = Db::name('order')->where('order_no',$order_no)->value('id');
            $invoice = Db::name('order_invoice')->where('order_id',$order_id)->find();
            if ($invoice['invoice_type'] == 3) {
                $dl_address = empty($invoice['invoice_dl_address']) ? '电子发票尚未出具，请联系商家出具后重试' : $invoice['invoice_dl_address'];
            } else {
                switch ($invoice['invoice_type']) {
                    case 1:
                        $invoice_type = '普通发票';
                        break;
                    case 2:
                        $invoice_type = '增值税发票';
                        break;
                    default:
                        $invoice_type = '普通发票';
                }
                $dl_address = '订单发票类型为:{$invoice_type}，请联系商家出具电子发票后重试';
            }
            $result[$order_no] = $dl_address;
        }
        return $this -> create($result);
    }
}


?>